package com.proj.springbootdemo.utils;

import base.exception.LogicException;
import lombok.Getter;

/**
 * @author liujia
 */
public enum Errors {
    // 测试用错误
    TESTERROR("SYS001", "测试用错误"),
    ;

    @Getter
    private final String code;
    @Getter
    private final String message;

    Errors(String code, String message) {
        this.code = code;
        this.message = message;
    }

    public static Errors of(String code) {
        for (Errors val : Errors.values()) {
            if (val.getCode().equals(code)) {
                return val;
            }
        }
        return null;
    }

    public LogicException exception() {
        return new LogicException(getCode(), getMessage());
    }

}
